package com.audaque.springboot.foshanupload.web.webdemo.controller;

import cn.hutool.json.JSON;
import cn.hutool.json.JSONConfig;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.audaque.springboot.foshanupload.log.anno.WebLogAnno;
import com.audaque.springboot.foshanupload.web.webdemo.model.domain.Country;
import com.audaque.springboot.foshanupload.web.webdemo.model.domain.Person;
import com.audaque.springboot.foshanupload.web.webdemo.model.dto.DateJacksonSerializeDto;
import com.audaque.springboot.foshanupload.web.webdemo.model.qo.DateJacksonDesSerializeQo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Date;


/**
 * @author zgb
 * @desc ...
 * @date 2022-01-25 22:13:31
 */
@Slf4j
@RestController
@RequestMapping("hutoolSerialize")
public class HutoolSerializeController {


    @WebLogAnno
    @GetMapping("/dateJacksonSerializeMpgtDto")
    public DateJacksonSerializeDto dateJacksonSerializeMpgtDto() throws Exception {
        DateJacksonSerializeDto dateJacksonSerializeDto = new DateJacksonSerializeDto();
        dateJacksonSerializeDto.setId(9223372036854775807L);
        dateJacksonSerializeDto.setUpdateDate(new Date());
        dateJacksonSerializeDto.setEventDate(new Date());
        dateJacksonSerializeDto.setCreateDate(new Date());
        dateJacksonSerializeDto.setMask("666");
        dateJacksonSerializeDto.setMaskEn("abc内容123");
        dateJacksonSerializeDto.setRsaEn("abc内容123");
        //dateJacksonSerializeDto.setRsaDe("E280eh0ln75TemdUUkUuUxRVROovBPNTOoIg2ICJw+gJoOk29BN8zthuqWezSsd5X52b8lzAinLbICPOL11ylClK3LTaSvCRUUcK5fwZ8EqDiMn6KOxcjg0XbyaoxuS5zyd1pVhXZnGkDe0MeMBQLLy3kTfj9Z+K4AfsacuZa4vA/a1dDPaTAp4tQP81eBkpbGPeDsFaYJBdtd7vr3g//BrruW1MyIMIXMaFwT3V9/rRJfrPTkT2ybFBdTw7n7ySopbVNRP5fLtaDc44GJiiKfB1Cb/vxzmGan/FIDc2QxN5IdWYvRQhnTDKXB+tvBLAdpApD/qfESG1twkt/r4B4Q==");
        dateJacksonSerializeDto.setItemCode("itemCode");
        return dateJacksonSerializeDto;

    }

    @WebLogAnno
    @GetMapping("/dateJacksonDesSerializeMpgtQo")
    public String dateJacksonDesSerializeMpgtQo(@RequestBody DateJacksonDesSerializeQo dateJacksonDesSerializeQo) throws Exception {
        return JSONUtil.toJsonStr(dateJacksonDesSerializeQo);
    }

    @WebLogAnno
    @GetMapping("/dateJacksonDesSerializeMpgtQo2")
    public String dateJacksonDesSerializeMpgtQo2(@RequestBody DateJacksonDesSerializeQo dateJacksonDesSerializeQo) throws Exception {
        return JSONUtil.toJsonStr(dateJacksonDesSerializeQo);
    }

    @WebLogAnno
    @GetMapping("/toJsonStr")
    public String toJsonStr() throws Exception {
        Person person = new Person();
        person.setDescribe("");
        person.setId("1");
        person.setSource(new BigDecimal("0"));
        person.setHeight(0.0D);
        person.setCreateTime(new Date());
        person.setBirthDate(new Date());
        person.setPersonCountry(new Country());
        return JSONUtil.toJsonStr(person);
    }

    @WebLogAnno
    @GetMapping("/parse")
    public JSON parse() throws Exception {
        Person person = new Person();
        person.setDescribe("");
        person.setId("1");
        person.setSource(new BigDecimal("0"));
        person.setHeight(0.0D);
        person.setCreateTime(new Date());
        person.setBirthDate(new Date());
        person.setPersonCountry(new Country());
        return JSONUtil.parse(JSONUtil.toJsonStr(person));
    }

    @WebLogAnno
    @GetMapping("/toJsonStr2")
    public String toJsonStr2() throws Exception {
        Person person = new Person();
        person.setDescribe("");
        person.setId("1");
        person.setSource(new BigDecimal("0"));
        person.setHeight(0.0D);
        person.setCreateTime(new Date());
        person.setBirthDate(new Date());
        person.setPersonCountry(new Country());
        //配置
        JSONConfig jsonConfig = JSONConfig.create();
        jsonConfig.setIgnoreNullValue(false);
        return JSONUtil.toJsonStr(person, jsonConfig);
    }

    @WebLogAnno
    @GetMapping("/parse2")
    public JSON parse2() throws Exception {
        Person person = new Person();
        person.setDescribe("");
        person.setId("1");
        person.setSource(new BigDecimal("0"));
        person.setHeight(0.0D);
        person.setCreateTime(new Date());
        person.setBirthDate(new Date());
        person.setPersonCountry(new Country());
        //配置
        JSONConfig jsonConfig = JSONConfig.create();
        jsonConfig.setIgnoreNullValue(false);
        return JSONUtil.parseObj(JSONUtil.toJsonStr(person, jsonConfig), false);
    }

    @WebLogAnno
    @GetMapping("/parse3")
    public Person parse3() throws Exception {
        Person person = new Person();
        person.setDescribe("");
        person.setId("1");
        person.setSource(new BigDecimal("0"));
        person.setHeight(0.0D);
        person.setCreateTime(new Date());
        person.setBirthDate(new Date());
        person.setPersonCountry(new Country());
        //配置
        JSONConfig jsonConfig = JSONConfig.create();
        jsonConfig.setIgnoreNullValue(false);
        JSONObject jsonObject = JSONUtil.parseObj(JSONUtil.toJsonStr(person, jsonConfig), false);
        return JSONUtil.toBean(jsonObject, Person.class);
    }

}
